﻿<UserControl x:Class="KeyboardImageViewer.TagAutoCompleteTextBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
        <Style x:Key="ListItemStyle" TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected" Value="false" />
                        <Condition Property="IsMouseOver" Value="true" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="{StaticResource HoverBrush}"/>
                </MultiTrigger>
            </Style.Triggers>
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Padding" Value="2,0,2,0" />
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListItem_MouseDown" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <TextBox
            Name="tags"
            Height="23"
            VerticalAlignment="Top"
            TextChanged="tags_TextChanged"
            PreviewKeyDown="tags_PreviewKeyDown"/>
        <Popup
            Name="tagPopup"
            Height="Auto"
            Width="Auto"
            StaysOpen="False"
            Placement="Bottom"
            IsOpen="False"
            HorizontalAlignment="Left"
            Closed="tagPopup_Closed">
            <Grid Width="Auto" Height="Auto">
                <ListBox
                    Name="tagListBox"
                    ScrollViewer.HorizontalScrollBarVisibility="Auto"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                    SelectedIndex="0"
                    SelectionMode="Single"
                    ItemContainerStyle="{StaticResource ListItemStyle}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding TagText}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <ListBox.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{StaticResource SelectColor}" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{StaticResource SelectColor}" />
                    </ListBox.Resources>
                </ListBox>
            </Grid>
        </Popup>
    </Grid>
</UserControl>
